home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000092_icon-group-sender _Sat May 15 20:32:40 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  2KB

  1. Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 17 May 1993 07:43:00 MST
  2. Received: by owl.cs.arizona.edu; Mon, 17 May 1993 07:42:58 MST
  3. Message-Id: <9305160132.AA01794@relay2.UU.NET>
  4. Subject: Re: string stripping
  5. To: uunet!cs.arizona.edu!icon-group@uunet.UU.NET (Icon News Group)
  6. Date: Sat, 15 May 1993 20:32:40 -0500 (CDT)
  7. From: Jerry Nowlin <isidev!nowlin@uunet.UU.NET>
  8. X-Mailer: ELM [version 2.4 PL21]
  9. Content-Type: text
  10. Content-Length: 1577      
  11. Status: R
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13.  
  14. > John David Stone Writes...
  15. >
  16. >         For stripping hyphens and dots out of a string, Steve Holden
  17. > suggests:
  18. >                 full ? {
  19. >                     while bare ||:= tab(many(~badchars)) do
  20. >                        tab(many(badchars))
  21. >                 }
  22. > which is tempting, but incorrectly sets bare to "" whenever the value of
  23. > full begins with a dot or hyphen.
  24.  
  25. I'm often amazed at how compact you can implement what appear to be
  26. complicated algorithms in Icon.  String scanning sometimes seems like there
  27. has to be a more elegant way but look how cool it is already!  There are
  28. two ways I could make this work.  Both require more code.  The first is
  29. more straightforward:
  30.  
  31.                 full ?  until pos(0) do {
  32.                         bare ||:= tab(many(~badchars))
  33.                         tab(many(badchars))
  34.                 }
  35.  
  36. Notice that the order in which the two matching expressions occur makes no
  37. difference.  The second solution requires an initial attempt to skip over
  38. badchars and is closer to the original:
  39.  
  40.                 full ?  {
  41.                     tab(many(badchars))
  42.                     while bare ||:= tab(many(~badchars)) do
  43.                        tab(many(badchars))
  44.                 }
  45.  
  46. I like the first solution.  Fewer lines, less mess, incomplete sentence.
  47. Both use the principle that failure does not have to be a bad thing.  I
  48. know I know...I submitted a code fragment.  Anyone who can't reconstitute
  49. this on their own just email me for a complete program.
  50.  
  51. Jerry Nowlin  -  uunet!isidev!nowlin  -  isidev!nowlin@uunet.uu.net
  52.  
  53.